﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TotalSystems.DataAccess;
using TotalSystems.Business.Public;

namespace TotalSystems.Business.Store
{
    public class RegimentationStuffRepository
    {
        TSContext _context = new TSContext();
        FinancialYearRepository financialYearRepository = new Public.FinancialYearRepository();

        #region Select
        public IEnumerable<STR_RegimentationStuff> GetRegimentationStuff()
        {
            return _context.STR_RegimentationStuff;
        }

        #endregion

        #region Insert

        public void InsertRegimentationStuff(STR_RegimentationStuff sTR_RegimentationStuff)
        {
            sTR_RegimentationStuff.ACC_Fy_ID_fk = financialYearRepository.GetACC_FinancialYearActive().Select(x => x.ACC_Fy_ID_fk).First();
            _context.AddToSTR_RegimentationStuff(sTR_RegimentationStuff);
            _context.SaveChanges();
        }

        #endregion

        #region Update

        public void UpdateRegimentationStuff(STR_RegimentationStuff sTR_RegimentationStuff)
        {
            var q = _context.STR_RegimentationStuff.FirstOrDefault(x => x.STR_Rs_ID == sTR_RegimentationStuff.STR_Rs_ID);
            _context.STR_RegimentationStuff.ApplyCurrentValues(q);
            _context.SaveChanges();
        }

        #endregion
    }
}
